package com.huilan.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huilan.mapper.UserMapper;
import com.huilan.model.User;
import com.huilan.service.UserService;
import com.huilan.util.PageUtil;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author ghy
 * @since 2019-04-19
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    UserMapper userMapper;
    /**
     * 获取用户列表
     */
    public List<User> getUserList() {
        return userMapper.selectList(null);
    }

    /**
     * 获取用户列表-分页
     *
     * @param page 分页
     * @return
     */
    public IPage getUserPageList(PageUtil<User> page) {
        return userMapper.selectPage(page,null);
    }


    /**
     * 根据名称查询用户
     *
     * @param userName
     * @return
     */
    public User selectUserByName(String userName) {
        Map<String,Object> map = new HashMap<String,Object>();
        map.put(User.USERNAME,userName);
        List<User> list = userMapper.selectByMap(map);
        return list.size()==1?list.get(0):null;
    }
}
